package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsClusterConfig;
import com.econ.powercloud.ems.dal.mapper.EmsClusterConfigMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description : EmsClusterConfig DAO层
 * @Date : 2021/11/3 10:27
 * @Modified by : zjf
 */
@Repository
public class EmsClusterConfigDAO extends ServiceImpl<EmsClusterConfigMapper, EmsClusterConfig> {

    /**
     * 通过簇code获取数据
     */
    public EmsClusterConfig getByDeviceCode(String deviceCode){
        LambdaQueryWrapper<EmsClusterConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(EmsClusterConfig::getDeviceCode,deviceCode);
        return this.baseMapper.selectOne(lambdaQueryWrapper);
    }

    public List<EmsClusterConfig> selectByDeviceCodes(List<String> deviceCodes){
        LambdaQueryWrapper<EmsClusterConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(EmsClusterConfig::getDeviceCode,deviceCodes);
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }

    public int deleteByDeviceCodes(List<String> deviceCodes){
        LambdaQueryWrapper<EmsClusterConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(EmsClusterConfig::getDeviceCode,deviceCodes);
        return this.baseMapper.delete(lambdaQueryWrapper);
    }

    public List<EmsClusterConfig> selectByType(Integer type){
        LambdaQueryWrapper<EmsClusterConfig> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(EmsClusterConfig::getType,type);
        return this.baseMapper.selectList(lambdaQueryWrapper);
    }
}
